import { msgData } from "@/i18n";

import { TableColumnData } from "@arco-design/web-vue";

export const translate = (moduleName: string): Ref<any> => {
  return computed(() => {
    if (!msgData.value) {
      return {};
    }
    return msgData.value?.[moduleName] || {};
  });
};
export const translateColumns = (columns: TableColumnData[]) => {
  const t = translate("公共模块");
  return columns.map((e) => {
    e.ellipsis = true;
    e.tooltip = true;

    e.slotName = `${e.dataIndex}`;
    e.title = t.value?.[e.title] || e.title;
    e.align = "center";
    if (!e.slotName) {
      e.slotName = e.dataIndex;
      e.tooltip = false;
    }
    return e;
  });
};
/* 翻译Options */
export const translateOptions = (options: any[]) => {
  const t = translate("公共模块");
  if (!options) return [];
  return options.map((e) => {
    e.label = t.value?.[e.label] || e.label;
    return e;
  });
};
